package com.zhangtai.modules.controller.admin;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.zhangtai.Neusoft.service.NeuEmployeeBaseInfoService;
import com.zhangtai.modules.controller.aouthLogin.LoginController;
import com.zhangtai.modules.dao.ContractUrlDao;
import com.zhangtai.modules.dao.EmployeeEducationDao;
import com.zhangtai.modules.dao.ImgUrlDao;
import com.zhangtai.modules.dao.RelativeRecordsDao;
import com.zhangtai.modules.dto.EmployeeInfoDto;
import com.zhangtai.modules.dto.OldEmployeeDto;
import com.zhangtai.modules.entity.common.ContractUrlEntity;
import com.zhangtai.modules.entity.common.ImgUrlEntity;
import com.zhangtai.modules.entity.employee.*;
import com.zhangtai.modules.service.baseFromMssql.BaseMssqlServiceImpl;
import com.zhangtai.modules.service.common.ImgUrlService;
import com.zhangtai.modules.service.employee.*;
import com.zhangtai.modules.vo.*;
import com.zhangtai.utils.AESUtil;
import com.zhangtai.utils.BeanUtilsMabach;
import com.zhangtai.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: ming
 * @Date: 2020/6/15 0015 下午 1:36
 */
@Api(tags="H5会员端接口")
@RestController
@RequestMapping("member")
@Slf4j
public class MemberController {
    @Autowired
    private EmployeeInfoService employeeInfoService;

    @Autowired
    private EmployeeInorgnameService employeeInorgnameService;
    @Autowired
    private EmployessSocietyexperienceService employessSocietyexperienceService;
    @Autowired
    private FamilyMemberService familyMemberService;
    @Autowired
    private ImgUrlService imgUrlService;
    @Autowired
    private LoginController loginController;
    @Autowired
    private ImgUrlDao imgUrlDao;
    @Autowired
    private EmployeeBpmService employeeBpmService;


    @Autowired
    private EmployeeEducationService employeeEducationService;
    @Autowired
    BaseMssqlServiceImpl jobService;
    @Autowired
    private EmployeeEducationDao employeeEducationDao;
    @Autowired
    private ContractUrlDao contractUrlDao;
    @Autowired
    private EmployerCompanyService employerCompanyService;
    @Autowired
    private RelativeRecordsDao relativeRecordsDao;
    @Autowired
    private RelativeRecordsService relativeRecordsService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private JobController jobController;

//    @Autowired
//    private NeuEmployeeBaseInfoService neuEmployeeBaseInfoService;

    @Autowired
    private EmployeeRecruitmentService employeeRecruitmentService;


    @GetMapping("/getEmployeeById/{id}")
    @ApiOperation(value="根据员工id获取详情(从现有库中查询)")
    // @SysLog(value ="测试[{{id}}]备份",operationType = OperationType.SELECT)
    public R<EmployeeInfoDto> findEmployeeByOid(@PathVariable("id") Long id,@RequestParam(value = "token",required = false)String token) {
        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(id);
        if (ObjectUtils.isEmpty(employeeInfoEntity)){
            return R.ok();
        }
        String entityToken = employeeInfoEntity.getToken();
        if (!StringUtils.isEmpty(token)){
            if (!token.equalsIgnoreCase(entityToken)){
                return R.error("token非法");
            }
        }


        Long oid = employeeInfoEntity.getOid();

        List<EmployeeEducationEntity> educationEntities = employeeEducationService.findEmployeeEducationListByOid(oid);
        List<EmployeeInorgnameEntity> inorgnameEntityList = employeeInorgnameService.getByEmpId(oid);
//        log.info("政治面貌:{}",inorgnameEntityList);
        List<EmployessSocietyexperienceEntity> societyexperienceEntities = employessSocietyexperienceService.getByEmpId(oid);
        //查询员工合同记录
        List<ContractUrlEntity> contractList= contractUrlDao.selectList(new QueryWrapper<ContractUrlEntity>().eq("is_delete",0).eq("id_card",employeeInfoEntity.getIdcard()).isNotNull("contract_oss_url"));
        List<FamilyMemberEntity> familyMemberEntities = familyMemberService.getListByEmpId(oid);
        //        亲属报备
        List<RelativeRecordsEntity> relativeRecordsEntities = relativeRecordsDao.selectList(new QueryWrapper<RelativeRecordsEntity>().eq("oid", oid).eq("is_delete", 0));

        EmployeeInfoDto employeeInfoDto = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeInfoDto.class);
        employeeInfoDto.setEmployeeEducation(educationEntities);
        employeeInfoDto.setEmployeeInorgname(inorgnameEntityList);
        employeeInfoDto.setFamilyMember(familyMemberEntities);
        employeeInfoDto.setEmployeeSociety(societyexperienceEntities);
        employeeInfoDto.setContractList(contractList);
        employeeInfoDto.setRelativeRecordsEntities(relativeRecordsEntities);


        getImg(oid, employeeInfoDto); //封装图片

        setParam(employeeInfoEntity, employeeInfoDto); //封装名称

        Long employerCompanyId = employeeInfoEntity.getEmployerCompanyId();
        EmployerCompanyEntity byIdE = employerCompanyService.getByIdE(employerCompanyId);
        if (!ObjectUtils.isEmpty(byIdE)){
            //        封装甲方单位
            employeeInfoDto.setEmployerCompany(byIdE.getName());
        }


//        封装复职员工信息
        Integer isReinstate = employeeInfoEntity.getIsReinstate(); //0:新员工，1：复职员工，2：旧员工
        Integer i=1;
        if (i.equals(isReinstate)){
            EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(oid);
            if (!ObjectUtils.isEmpty(employeeBpmEntity)){
                OldEmployeeDto oldEmployeeDto = BeanUtilsMabach.doToDto(employeeBpmEntity, OldEmployeeDto.class);
                employeeInfoDto.setOldEmployeeDto(oldEmployeeDto);
            }
        }



        return R.ok(employeeInfoDto);
    }




    @PostMapping("/getEmployeeByIdAuth")
    @ApiOperation(value="根据员工id获取详情(从现有库中查询)")
    // @SysLog(value ="测试[{{id}}]备份",operationType = OperationType.SELECT)
    public R<EmployeeInfoDto> findEmployeeByOidAuth(@RequestBody String id) {
//        try {
//            id = java.net.URLDecoder.decode(id, "UTF-8");
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
        JSONObject jsonobject = JSONObject.parseObject(id);
            System.out.println("id:"+id.length());
        System.out.println(id);
        id= (String) jsonobject.get("id");
//        id="ONXmUV/obkbpPz4DOXDsp6EDJ9ZNz5r6t5j49S/1PbM=";  ZjixQ/9dWpdvel4 Xkzzkj2pf71c/8TITXvzMJj0k4w=
        String aesId =AESUtil.aesDecryptH5(id);

        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(new Long(aesId));
        if (ObjectUtils.isEmpty(employeeInfoEntity)){
            return R.ok();
        }
//        String entityToken = employeeInfoEntity.getToken();
//        if (!StringUtils.isEmpty(token)){
//            if (!token.equalsIgnoreCase(entityToken)){
//                return R.error("token非法");
//            }
//        }


        Long oid = employeeInfoEntity.getOid();

        List<EmployeeEducationEntity> educationEntities = employeeEducationService.findEmployeeEducationListByOid(oid);
        List<EmployeeInorgnameEntity> inorgnameEntityList = employeeInorgnameService.getByEmpId(oid);
//        log.info("政治面貌:{}",inorgnameEntityList);
        List<EmployessSocietyexperienceEntity> societyexperienceEntities = employessSocietyexperienceService.getByEmpId(oid);
        //查询员工合同记录
        List<ContractUrlEntity> contractList= contractUrlDao.selectList(new QueryWrapper<ContractUrlEntity>().eq("is_delete",0).eq("id_card",employeeInfoEntity.getIdcard()).isNotNull("contract_oss_url"));
        List<FamilyMemberEntity> familyMemberEntities = familyMemberService.getListByEmpId(oid);
        //        亲属报备
        List<RelativeRecordsEntity> relativeRecordsEntities = relativeRecordsDao.selectList(new QueryWrapper<RelativeRecordsEntity>().eq("oid", oid).eq("is_delete", 0));

        EmployeeInfoDto employeeInfoDto = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeInfoDto.class);
        employeeInfoDto.setEmployeeEducation(educationEntities);
        employeeInfoDto.setEmployeeInorgname(inorgnameEntityList);
        employeeInfoDto.setFamilyMember(familyMemberEntities);
        employeeInfoDto.setEmployeeSociety(societyexperienceEntities);
        employeeInfoDto.setContractList(contractList);
        employeeInfoDto.setRelativeRecordsEntities(relativeRecordsEntities);


        getImg(oid, employeeInfoDto); //封装图片

        setParam(employeeInfoEntity, employeeInfoDto); //封装名称

        Long employerCompanyId = employeeInfoEntity.getEmployerCompanyId();
        EmployerCompanyEntity byIdE = employerCompanyService.getByIdE(employerCompanyId);
        if (!ObjectUtils.isEmpty(byIdE)){
            //        封装甲方单位
            employeeInfoDto.setEmployerCompany(byIdE.getName());
        }


//        封装复职员工信息
        Integer isReinstate = employeeInfoEntity.getIsReinstate(); //0:新员工，1：复职员工，2：旧员工
        Integer i=1;
        if (i.equals(isReinstate)){
            EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(oid);
            if (!ObjectUtils.isEmpty(employeeBpmEntity)){
                OldEmployeeDto oldEmployeeDto = BeanUtilsMabach.doToDto(employeeBpmEntity, OldEmployeeDto.class);
                employeeInfoDto.setOldEmployeeDto(oldEmployeeDto);
            }
        }



        return R.ok(employeeInfoDto);
    }


    @PostMapping("/updateMainInfo")
    @ApiOperation(value="修改新员工主体信息")
    @Transactional
    public R updateMainInfo(@RequestBody @Valid MemberEmpBpmUpdateVo memberEmpBpmUpdateVo,@RequestParam(value = "token",required = false)String token){

       Long oid = memberEmpBpmUpdateVo.getOid();
        EmployeeInfoEntity entity = employeeInfoService.getByIdE(oid);
        String entityToken = entity.getToken();
        if (!StringUtils.isEmpty(token)){
            if (token.equals(entityToken)){
                return R.error("token非法");
            }

            Object o = redisTemplate.boundValueOps(token).get();
            if (ObjectUtils.isEmpty(o)){
                return R.error("已确认入职，无法修改");
            }
        }


        Boolean flag=false;
        EmployeeInfoEntity employeeInfoEntity = BeanUtilsMabach.doToDto(memberEmpBpmUpdateVo, EmployeeInfoEntity.class);

        String disbandment = memberEmpBpmUpdateVo.getDisbandment();
        if ("0".equals(disbandment)){
            employeeInfoEntity.setVeteranNum("");
        }
//        封装保存图片的方法
        Long id = saveImg(memberEmpBpmUpdateVo);

//        employeeInfoEntity.setIsMemberDone(1);


        BigDecimal oldSalary = memberEmpBpmUpdateVo.getOldSalary();
        BigDecimal oldPerformance = memberEmpBpmUpdateVo.getOldPerformance();
        EmployeeBpmEntity employeeBpmEntity=null;
        if (oldSalary!=null){
           employeeBpmEntity = employeeBpmService.getByIdE(id);
            if (ObjectUtils.isEmpty(employeeBpmEntity)){
                return R.error("根据员工id查询bpm表为空");
            }
            employeeBpmEntity.setOldSalary(oldSalary);
            employeeBpmService.updateByIdE(employeeBpmEntity);
        }
        if (oldPerformance!=null){

            employeeBpmEntity = employeeBpmService.getByIdE(id);
            if (ObjectUtils.isEmpty(employeeBpmEntity)){
                return R.error("根据员工id查询bpm表为空");
            }
            employeeBpmEntity.setOldPerformance(oldPerformance);
            employeeBpmService.updateByIdE(employeeBpmEntity);
        }
        employeeInfoEntity.setUpdateTime(new Date());
        employeeInfoService.updateByIdE(employeeInfoEntity);

        //修改招聘数据信息
        EmployeeInfoEntity entity1= employeeInfoService.getByIdE(employeeInfoEntity.getOid());
        if(!StringUtils.isEmpty(entity1.getRecruitmentId())){
            EmployeeRecruitmentEntity employeeRecruitmentEntity = BeanUtilsMabach.doToDto(employeeInfoEntity, EmployeeRecruitmentEntity.class);
            employeeRecruitmentEntity.setId(entity1.getRecruitmentId());
            employeeRecruitmentService.updateByIdE(employeeRecruitmentEntity);
        }

        //同步到ehr
//        neuEmployeeBaseInfoService.saveEmpBaseInfo(employeeInfoEntity.getOid());

        flag=true;
        if (flag){
            return R.ok();
        }
        return R.error();
    }


    @PostMapping("/updateOldSalary")
    @ApiOperation(value="修改员工原单位薪资")
    public R updateOldSalary(@RequestBody @Valid OldSalaryVo oldSalaryVo){
        EmployeeBpmEntity employeeBpmEntity = employeeBpmService.getByIdE(oldSalaryVo.getOid());
        if (ObjectUtils.isEmpty(employeeBpmEntity)){
            return R.error("根据oid查询员工BPM表为空");
        }
        BigDecimal oldPerformance = oldSalaryVo.getOldPerformance();
        if (oldPerformance!=null){
            employeeBpmEntity.setOldPerformance(oldPerformance);
        }
        employeeBpmEntity.setOldSalary(oldSalaryVo.getOldSalary());
        return employeeBpmService.updateByIdE(employeeBpmEntity);

    }



    @GetMapping("/deleteMainInfo/{id}")
    @ApiOperation(value="删除新员工主体信息")
    public R deleteMainInfo(@PathVariable("id")  Long  id){

        R r = employeeInfoService.removeOneById(id);
        return r;
    }


    @GetMapping("/getEducationInfo/{empoid}")
    @ApiOperation(value="获取员工教育信息")
    public R<List<EmployeeEducationEntity>> getEducationInfo(@PathVariable("empoid")  Long  empoid) {
        List<EmployeeEducationEntity> byEmpId = employeeEducationService.findEmployeeEducationListByOid(empoid);
        return R.ok(byEmpId);
    }

    @PostMapping("/saveEducationInfo")
    @ApiOperation(value="添加新员工教育信息")
    public R saveEducationInfo(@RequestBody @Valid EmployeeEducationVo employeeEducationVo){
        EmployeeEducationEntity employeeEducationEntity = BeanUtilsMabach.doToDto(employeeEducationVo, EmployeeEducationEntity.class);
//        employeeEducationEntity.setOperatetime(new Date());
        R r = employeeEducationService.saveE(employeeEducationEntity);
        return r;
    }

    @PostMapping("/updateEducationInfo")
    @ApiOperation(value="修改员工教育信息")
    public R updateEducationInfo(@RequestBody @Valid EmployeeEducationUpdateVo employeeEducationVo){
//        log.info("employeeEducationVo参数:{}",employeeEducationVo);
        EmployeeEducationEntity employeeEducationEntity = BeanUtilsMabach.doToDto(employeeEducationVo, EmployeeEducationEntity.class);
//        employeeEducationEntity.setOperatetime(new Date());
//        R r = employeeEducationService.updateByIdE(employeeEducationEntity);
        int i = employeeEducationDao.updateById(employeeEducationEntity);
        if (i>0){
            return R.ok();
        }else {
            return R.error();
        }


    }

    @GetMapping("/deleteEducation/{id}")
    @ApiOperation(value="删除员工教育信息")
    public R deleteEducation(@PathVariable("id")  Long  id){

        R r = employeeEducationService.removeOneById(id);
        return r;
    }

    @GetMapping("/getInorgInfo/{empoid}")
    @ApiOperation(value="获取员工政治面貌")
    public R<List<EmployeeInorgnameEntity>> getInorgInfo(@PathVariable("empoid")  Long  empoid) {
        List<EmployeeInorgnameEntity> byEmpId = employeeInorgnameService.getByEmpId(empoid);
        return R.ok(byEmpId);
    }

    @PostMapping("/saveInorgInfo")
    @ApiOperation(value="添加新政治面貌信息")
    public R saveInorg(@RequestBody @Valid EmployeeInorgnameVo employeeInorgnameVo){
        EmployeeInorgnameEntity employeeInorgnameEntity = BeanUtilsMabach.doToDto(employeeInorgnameVo, EmployeeInorgnameEntity.class);
        employeeInorgnameEntity.setOperatetime(new Date());
        R r = employeeInorgnameService.saveE(employeeInorgnameEntity);
//        log.info("入党：{}",employeeInorgnameVo);
        return r;
    }

    @PostMapping("/updateInorgInfo")
    @ApiOperation(value="修改新员工政治面貌信息")
    public R updateInorg(@RequestBody @Valid EmployeeInorgnameUpdateVo employeeInorgnameUpdateVo){
        EmployeeInorgnameEntity employeeInorgnameEntity = BeanUtilsMabach.doToDto(employeeInorgnameUpdateVo, EmployeeInorgnameEntity.class);
        employeeInorgnameEntity.setOperatetime(new Date());
        R r = employeeInorgnameService.updateByIdE(employeeInorgnameEntity);
        return r;
    }

    @GetMapping("/deleteInorg/{id}")
    @ApiOperation(value="删除员工政治面貌信息")
    public R deleteInorg(@PathVariable("id")  Long  id){

        R r = employeeInorgnameService.removeOneById(id);
        return r;
    }

    @PostMapping("/saveSociety")
    @ApiOperation(value="添加新员工作履历")
    public R saveSociety(@RequestBody @Valid EmployessSocietyVo employessSocietyVo){
        Long empoid = employessSocietyVo.getEmpoid();
        EmployeeInfoEntity byIdE = employeeInfoService.getByIdE(empoid);
        if (ObjectUtils.isEmpty(byIdE)){
            return R.error("查不到该员工主体信息");
        }
        EmployessSocietyexperienceEntity employessSocietyexperienceEntity = BeanUtilsMabach.doToDto(employessSocietyVo, EmployessSocietyexperienceEntity.class);
        employessSocietyexperienceEntity.setOperatetime(new Date());
        R r = employessSocietyexperienceService.saveE(employessSocietyexperienceEntity);

        return r;
    }

    @GetMapping("/getSociety/{empoid}")
    @ApiOperation(value="获取员工作履历信息")
    public R<List<EmployessSocietyexperienceEntity>> getSociety(@PathVariable("empoid")  Long  empoid) {
        List<EmployessSocietyexperienceEntity> byEmpId = employessSocietyexperienceService.getByEmpId(empoid);
        return R.ok(byEmpId);
    }

    @PostMapping("/updateSociety")
    @ApiOperation(value="修改新员工作履历")
    public R updateSociety(@RequestBody @Valid EmployessSocietyUpdateVo employessSocietyVo){
        EmployessSocietyexperienceEntity employessSocietyexperienceEntity = BeanUtilsMabach.doToDto(employessSocietyVo, EmployessSocietyexperienceEntity.class);
        employessSocietyexperienceEntity.setOperatetime(new Date());
        R r = employessSocietyexperienceService.updateByIdE(employessSocietyexperienceEntity);
        return r;
    }

    @GetMapping("/deleteSociety/{id}")
    @ApiOperation(value="删除员工工作履历")
    public R deleteSociety(@PathVariable("id")  Long  id){

        R r = employessSocietyexperienceService.removeOneById(id);
        return r;
    }

    
    @GetMapping("/getFamily/{empoid}")
    @ApiOperation(value="获取员工家庭信息")
    public R<List<FamilyMemberEntity>> getFamily(@PathVariable("empoid")  Long  empoid) {
        List<FamilyMemberEntity> byEmpId = familyMemberService.getListByEmpId(empoid);
        return R.ok(byEmpId);
    }
    @PostMapping("/saveFamily")
    @ApiOperation(value="添加新员工家庭联关系")
    @Transactional
    public R saveFamily(@RequestBody @Valid FamilyMemberVo employessSocietyVo){
        FamilyMemberEntity employessSocietyexperienceEntity = BeanUtilsMabach.doToDto(employessSocietyVo, FamilyMemberEntity.class);
        employessSocietyexperienceEntity.setOperatetime(new Date());
        R r = familyMemberService.saveE(employessSocietyexperienceEntity);
        return r;
    }

    @PostMapping("/updateFamily")
    @ApiOperation(value="修改员工家庭联关系")
    @Transactional
    public R updateFamily(@RequestBody @Valid FamilyMemberUpdateVo employessSocietyVo){
        FamilyMemberEntity employessSocietyexperienceEntity = BeanUtilsMabach.doToDto(employessSocietyVo, FamilyMemberEntity.class);
        employessSocietyexperienceEntity.setOperatetime(new Date());
        R r = familyMemberService.updateByIdE(employessSocietyexperienceEntity);
        return r;
    }

    @GetMapping("/deleteFamily/{id}")
    @ApiOperation(value="删除员工家庭成员信息")
    public R deleteFamily(@PathVariable("id")  Long  id){

        R r = familyMemberService.removeOneById(id);
        return r;
    }

    @GetMapping("/getRelativeRecords/{oid}")
    @ApiOperation(value="根据oid获取员工亲属报备信息")
    public R<List<RelativeRecordsEntity>> getRelativeRecords(@PathVariable("oid")Long oid,HttpServletRequest request)throws  Exception{

        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(oid);
        if(ObjectUtils.isEmpty(employeeInfoEntity)){
            return R.error("员工信息不存在");
        }
        List<RelativeRecordsEntity> relativeRecordsEntities = relativeRecordsDao.selectList(new QueryWrapper<RelativeRecordsEntity>().eq("oid", oid).eq("is_delete", 0));



        return R.ok(relativeRecordsEntities);
    }


    @PostMapping("/saveRelativeRecords")
    @ApiOperation(value="添加员工亲属报备信息")
    public R saveRelativeRecords(@RequestBody @Valid RelativeRecordsEntity relativeRecordsEntity,HttpServletRequest request)throws  Exception{

        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(relativeRecordsEntity.getOid());
        if(ObjectUtils.isEmpty(employeeInfoEntity)){
            return R.error("员工信息不存在");
        }


        R r = relativeRecordsService.saveE(relativeRecordsEntity);
        return r;
    }

    @PostMapping("/updateRelativeRecords")
    @ApiOperation(value="修改员工亲属报备信息")
    public R updateRelativeRecords(@RequestBody @Valid RelativeRecordsEntity relativeRecordsEntity, HttpServletRequest request)throws  Exception{

        EmployeeInfoEntity employeeInfoEntity = employeeInfoService.getByIdE(relativeRecordsEntity.getOid());
        if(ObjectUtils.isEmpty(employeeInfoEntity)){
            return R.error("员工信息不存在");
        }


        R r = relativeRecordsService.updateByIdE(relativeRecordsEntity);
        return r;
    }

    @DeleteMapping("/deleteRelativeRecords/{id}")
    @ApiOperation(value="删除员工亲属报备信息")
    public R deleteRelativeRecords(@PathVariable("id")Long id)throws  Exception{


        R r = relativeRecordsService.removeOneById(id);
        return r;
    }



    private Long saveImg(@RequestBody @Valid MemberEmpBpmUpdateVo memberEmpBpmUpdateVo) {
        Long id = memberEmpBpmUpdateVo.getOid();
//修改流水
        List<String> oldSalaryRecordUrl = memberEmpBpmUpdateVo.getOldSalaryRecordUrl();
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",1));
        if (!CollectionUtils.isEmpty(oldSalaryRecordUrl)){

            for (String s : oldSalaryRecordUrl) {
                ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
                imgUrlEntity.setName("原公司工资流水");
                imgUrlEntity.setOid(id);
                imgUrlEntity.setType(1);
                imgUrlEntity.setCreateTime(new Date());
                imgUrlEntity.setUrl(s);
                imgUrlService.saveE(imgUrlEntity);

            }
        }
//        照片
        String photoUrl = memberEmpBpmUpdateVo.getPhotoUrl();
        if (!StringUtils.isEmpty(photoUrl)){

            imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",0));
            ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
            imgUrlEntity.setType(0);
            imgUrlEntity.setOid(id);
            imgUrlEntity.setName("1寸照片");
            imgUrlEntity.setUrl(photoUrl);
            imgUrlEntity.setCreateTime(new Date());

            imgUrlService.saveE(imgUrlEntity);
        }

        //        毕业证
        String graduationUrl = memberEmpBpmUpdateVo.getGraduationUrl();
        if (!StringUtils.isEmpty(graduationUrl)){
            imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",2));
            ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
            imgUrlEntity.setType(2); //0:流水，1：头像，2：毕业证
            imgUrlEntity.setOid(id);
            imgUrlEntity.setName("毕业证");
            imgUrlEntity.setUrl(graduationUrl);
            imgUrlEntity.setCreateTime(new Date());
            imgUrlService.saveE(imgUrlEntity);
        }
//        学位证
        String degreeUrl = memberEmpBpmUpdateVo.getDegreeUrl();
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",3));
        if (!StringUtils.isEmpty(degreeUrl)){

            ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
            imgUrlEntity.setType(3); //0:流水，1：头像，2：毕业证,3:学位证
            imgUrlEntity.setOid(id);
            imgUrlEntity.setName("学位证");
            imgUrlEntity.setUrl(degreeUrl);
            imgUrlEntity.setCreateTime(new Date());
            imgUrlService.saveE(imgUrlEntity);
        }
//        离职证明
        String dimissionUrl = memberEmpBpmUpdateVo.getDimissionUrl();
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",4));
        if (!StringUtils.isEmpty(dimissionUrl)){
            ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
            imgUrlEntity.setType(4); //0:流水，1：头像，2：毕业证,3:学位证，4：离职证明
            imgUrlEntity.setOid(id);
            imgUrlEntity.setName("离职证明");
            imgUrlEntity.setUrl(degreeUrl);
            imgUrlEntity.setCreateTime(new Date());
            imgUrlService.saveE(imgUrlEntity);
        }

//        体检报告
        String healthUrl = memberEmpBpmUpdateVo.getHealthUrl();
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",5));
        if (!StringUtils.isEmpty(healthUrl)){
            ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
            imgUrlEntity.setType(5); //0:流水，1：头像，2：毕业证,3:学位证，4：离职证明,5：体检报告
            imgUrlEntity.setOid(id);
            imgUrlEntity.setName("体检报告");
            imgUrlEntity.setUrl(healthUrl);
            imgUrlEntity.setCreateTime(new Date());
            imgUrlService.saveE(imgUrlEntity);
        }
//        身份证
        List<String> idcardImgs = memberEmpBpmUpdateVo.getIdcardImgs();
        if (!CollectionUtils.isEmpty(idcardImgs)){
            imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",6));
            for (String idcardImg : idcardImgs) {
                ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
                imgUrlEntity.setType(6); //0:流水，1：头像，2：毕业证,3:学位证，4：离职证明,5：体检报告,6:身份证正反面
                imgUrlEntity.setOid(id);
                imgUrlEntity.setName("身份证");
                imgUrlEntity.setUrl(idcardImg);
                imgUrlEntity.setCreateTime(new Date());
                imgUrlService.saveE(imgUrlEntity);
            }

        }
        List<String> credential = memberEmpBpmUpdateVo.getCredential(); //证书
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",10));
        if (!CollectionUtils.isEmpty(credential)){
            for (String s : credential) {
                ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
                imgUrlEntity.setType(10); //0:流水，1：头像
                imgUrlEntity.setOid(id);
                imgUrlEntity.setName("职称证书");
                imgUrlEntity.setUrl(s);
                imgUrlEntity.setCreateTime(new Date());
                imgUrlService.saveE(imgUrlEntity);
            }
        }
        List<String> attachments = memberEmpBpmUpdateVo.getAttachments();
        imgUrlDao.delete(new QueryWrapper<ImgUrlEntity>().eq("oid",id).eq("type",11));
        if (!CollectionUtils.isEmpty(attachments)){
            for (String attachment : attachments) {
                ImgUrlEntity imgUrlEntity = new ImgUrlEntity();
                imgUrlEntity.setType(11); //0:流水，1：头像
                imgUrlEntity.setOid(id);
                imgUrlEntity.setName("其他附件");
                imgUrlEntity.setUrl(attachment);
                imgUrlEntity.setCreateTime(new Date());
                imgUrlService.saveE(imgUrlEntity);
            }
        }

        return id;
    }



    private void getImg(Long oid, EmployeeInfoDto employeeInfoDto) {
        //        如果薪资流水不为空，则封装进去
        List<ImgUrlEntity> imgUrlEntities = imgUrlDao.selectList(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 1));
        if (!CollectionUtils.isEmpty(imgUrlEntities)){
            ArrayList<String> recordUrls = new ArrayList<>();
            for (ImgUrlEntity imgUrlEntity : imgUrlEntities) {
                recordUrls.add(imgUrlEntity.getUrl());
            }
            employeeInfoDto.setOldSalaryRecordUrl(recordUrls);
        }
//        封装头像
        ImgUrlEntity imgUrlEntity = imgUrlDao.selectOne(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 0));
        if (!ObjectUtils.isEmpty(imgUrlEntity)){
            employeeInfoDto.setPhotoUrl(imgUrlEntity.getUrl());
        }

        //0:流水，1：头像，2：毕业证,3:学位证，4：离职证明,5：体检报告
        ImgUrlEntity imgUrlEntity2 = imgUrlDao.selectOne(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 2));
        if (!ObjectUtils.isEmpty(imgUrlEntity2)){
            employeeInfoDto.setGraduationUrl(imgUrlEntity2.getUrl());
        }
//        学位证
        ImgUrlEntity imgUrlEntity3 = imgUrlDao.selectOne(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 3));
        if (!ObjectUtils.isEmpty(imgUrlEntity3)){
            employeeInfoDto.setDegreeUrl(imgUrlEntity3.getUrl());
        }
//        离职证明
        ImgUrlEntity imgUrlEntity4 = imgUrlDao.selectOne(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 4));
        if (!ObjectUtils.isEmpty(imgUrlEntity4)){
            employeeInfoDto.setDimissionUrl(imgUrlEntity4.getUrl());
        }
//        体检报告
        ImgUrlEntity imgUrlEntity5 = imgUrlDao.selectOne(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 5));
        if (!ObjectUtils.isEmpty(imgUrlEntity5)){
            employeeInfoDto.setHealthUrl(imgUrlEntity5.getUrl());
        }

        //        身份证
        List<ImgUrlEntity> imgUrlEntityList = imgUrlDao.selectList(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 6));
        ArrayList<String> strings = new ArrayList<>();
        for (ImgUrlEntity urlEntity : imgUrlEntityList) {
            strings.add(urlEntity.getUrl());
        }
        if (!CollectionUtils.isEmpty(imgUrlEntityList)){
            employeeInfoDto.setIdcardImgs(strings);
        }
//职称
        List<ImgUrlEntity> imgUrlEntityList3 = imgUrlDao.selectList(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 10));
        ArrayList<String> strings1 = new ArrayList<>();
        if (!CollectionUtils.isEmpty(imgUrlEntityList3)){
            for (ImgUrlEntity urlEntity : imgUrlEntityList3) {
                strings1.add(urlEntity.getUrl());
            }
            employeeInfoDto.setCredential(strings1);
        }

//        其他附件

        List<ImgUrlEntity> imgUrlEntityList4 = imgUrlDao.selectList(new QueryWrapper<ImgUrlEntity>().eq("oid", oid).eq("type", 11));
        ArrayList<String> strings2 = new ArrayList<>();
        if (!CollectionUtils.isEmpty(imgUrlEntityList4)){
            for (ImgUrlEntity urlEntity : imgUrlEntityList4) {
                strings2.add(urlEntity.getUrl());
            }
            employeeInfoDto.setAttachments(strings2);
        }

    }

    private void setParam(EmployeeInfoEntity employeeInfoEntity, EmployeeInfoDto employeeInfoDto) {
        /**
         * 根据各种id查询名称
         */
        Long unitId = employeeInfoEntity.getUnitId();
        Long orgId = employeeInfoEntity.getOrgId();
        Long jobId = employeeInfoEntity.getJobId();

        Long jobSystemId = employeeInfoEntity.getJobSystemId();
        Long lineId = employeeInfoEntity.getLineId();


        Long jobLevelId = employeeInfoEntity.getJobLevelId();
        String jobLevelNameById = jobController.getJobLevelNameById(jobLevelId);
        employeeInfoDto.setJobLevel(jobLevelNameById);


        String systemNameById = jobController.getSystemNameById(jobSystemId);
//        log.info("OrgSystemEntity:{}",jobLevelById);

        employeeInfoDto.setJobSystem(systemNameById);

        String lineNameById = jobController.getLineNameById(lineId);

        employeeInfoDto.setLine(lineNameById);


        String org = jobController.getOrgNameById(orgId);
        employeeInfoDto.setOrgname(org);


        String unit = jobController.getOrgNameById(unitId);
        employeeInfoDto.setUnitname(unit);


        String jobName = jobController.getJobName(jobId);
        employeeInfoDto.setJobname(jobName);
    }








}
